package com.edu.eduservice.controller;


import com.edu.common.utils.R;
import com.edu.eduservice.service.EduSubjectService;
import com.edu.eduservice.vo.subjectTreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-05-30
 */
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
@Api(description = "课程分类管理")
public class EduSubjectController {
    @Autowired
    EduSubjectService eduSubjectService;

    //添加课程分类
    //获取上传文件,把文件读取出来
    @PostMapping("/addSubject")
    @ApiOperation(value = "Excel导入")
    @Transactional
    public R addSubject(MultipartFile file){

        eduSubjectService.saveSubject(file,eduSubjectService);

        return R.ok();
    }

    //课程分类列表
    @ApiOperation(value = "tree树形")
    @GetMapping("/tree")
    public R subjectTree(){
       List<subjectTreeVo> subjectTreeVo = eduSubjectService.SubjectList();

        return R.ok().data("tree",subjectTreeVo);
    }

}

